package com.example.demo.service;

import com.example.demo.common.domain.Hotel;
import com.example.demo.common.domain.HotelExample;
import com.example.demo.mapper.HotelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class SearchService {
    @Autowired
    private HotelMapper hotelMapper;
    @Autowired
    private HotelExample hotelExample;

    public List<Hotel> SearchHotel(String Destination, String KeyWord) {
        List<Hotel> HotelList;
        Boolean falgD = !(Destination.isEmpty() || Destination == null || Destination.equals("Type Here"));
        Boolean falgK = !(KeyWord.isEmpty() || KeyWord == null || KeyWord.equals("Type Here"));
        System.out.println("D:" + falgD + ",K:" + falgK);
        if (falgD && falgK) {
            hotelExample.createCriteria().andCityLike("%" + Destination + "%").andHotelTranslatedNameLike("%" + KeyWord + "%");
        }
        if (falgD == true && falgK == false) {
            hotelExample.createCriteria().andCityLike("%" + Destination + "%");
        }
        if (falgD == false && falgK == true) {
            hotelExample.createCriteria().andHotelTranslatedNameLike("%" + KeyWord + "%");
        }
        HotelList = hotelMapper.selectByExample(hotelExample);
        hotelExample.clear();
        return HotelList;
    }
}
